<!-- no-cache -->
<!-- no-header -->

{% extends "templates/web.html" %}

{% macro render_node(parent) %}
<ul class="tree">
{% for account in accounts %}
	{% if (account.parent_account or "") == parent %}
	<li>
		<span class="tree-link"
			data-name="{{ account.name }}"
			data-account-name="{{ account.account_name }}"
			data-account-number="{{ account.account_number }}"
			data-parent-account="{{ account.parent_account }}"
            data-account-type="{{ account.account_type }}"
			data-company="{{ account.company }}"
            data-is-group="{{ account.is_group }}"
            data-root-type="{{ account.root_type }}"
			data-tax-rate="{{ account.tax_rate }}">{{ account.name }}</span>

		{% if account.account_type %}
			<span class="label label-warning account-tag"> {{ account.account_type }} </span>
		{% endif %}

		<span class="tree-node-toolbar-wrapper" data-account-name="{{ account.account_name }}"></span>

		{% if account.is_group %}
			{{ render_node(account.name) }}
		{% endif %}
	</li>
	{% endif %}
{% endfor %}
</ul>
{% endmacro %}

{% block page_content %}

<!-- <style>{% include "chart_of_accounts_builder/www/chart.css" %}</style> -->

{% if frappe.user == "Guest" %}
<div class='alert alert-warning'>Please <a href="/login">login</a> to fork and edit this chart</div>
{% endif %}

<div>
	{% if frappe.user != "Guest" %}
		{% if frappe.form_dict.forked == "0" or (frappe.form_dict.submitted == "1" and frappe.session.user != frappe.form_dict.owner) %}
		<div class='alert alert-warning'>Please fork to edit this chart </div>
		{% endif %}

		{% if frappe.session.user == frappe.form_dict.owner and frappe.form_dict.submitted == "1" %}
			<button class="btn btn-default pull-right edit-chart">
				<span class="octicon octicon-pencil"></span>
				<span class="text">Edit</span>
			</button>
		{% endif %}

		{% if frappe.form_dict.forked == "1" and frappe.form_dict.submitted == "1" %}
			<button class="btn btn-default pull-right download-chart">
				<span class="octicon octicon-desktop-download"></span>
				<span class="text">Download</span>
			</button>
		{% endif %}

		{% if frappe.form_dict.forked == "0" or frappe.form_dict.submitted == "1" %}
			<button class="btn btn-default pull-right star-button">
					<span class="octicon octicon-star"></span>
					<span class="text">Star </span>
					<span class="star-count badge" style="background: #858585;">{{ stars }}</span>
			</button>

			{% if frappe.form_dict.forked == "0" or frappe.session.user != frappe.form_dict.owner %}
				<button class="btn btn-default pull-right fork-button">
					<span class="octicon octicon-repo-forked"></span>
					<span class="text">Fork</span>
				</button>
			{% endif %}

		{% elif frappe.form_dict.forked == "1" and frappe.form_dict.submitted == "0" %}
			<button class="btn btn-primary btn-accept pull-right submit-chart">
				<span class="octicon octicon-check"></span>
				<span class="text">Submit</span>
			</button>

			<button class="btn btn-default pull-right delete-chart">
				<span class="octicon octicon-x"></span>
				<span class="text">Delete</span>
			</button>
		{% endif %}
	{% endif %}

	<h2 class="chart-title">{{ frappe.sanitize_html(frappe.form_dict.company) }}</h2>
</div>

<hr style="margin-left: 0px; margin-right: 0px;">

<div>
	{{ render_node("") }}
	<ul class="tree tree-add-root">
		<li>
			<button class="btn btn-default add-root-button">
				<span class="octicon octicon-plus"></span>
				<span>Add Root Account</span>
			</button>
		</li>
	</ul>
</div>

{% include 'templates/includes/comments/comments.html' %}

<!-- <script>{% include "chart_of_accounts_builder/www/chart.js" %}</script> -->

{% endblock %}
